/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/6/21 0021 11:24
 * - Stay Hungry, Stay Foolish
 * - Just do it
 */
public class Solution {


    public int findCircleNum(int[][] M) {
        UnionFind unionFind = new UnionFind(M.length);
        for (int i = 0; i < M.length; i++) {
            for (int j = 0; j < M[i].length; j++) {
                if (i !=j && M[i][j] == 1) {
                    unionFind.unionElements(i, j);
                }
            }
        }
        return unionFind.findParents();
    }

    public static void main(String[] args) {
       /* int[][] test1 = new int[][]{
                {1, 1, 0},
                {1, 1, 0},
                {0, 0, 1}
        };*/

        //System.out.println(new Solution().findCircleNum(test1));

        int[][] test2 = new int[][]{
                {1, 1, 0},
                {1, 1, 1},
                {0, 1, 1}
        };

        System.out.println();
        System.out.println(new Solution().findCircleNum(test2));

    }

}
